﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEditor;
using LitJson;


public class CreateGoodJson
{

	[MenuItem("CreateJson/GoodJson")]
	public static void CreateJson()
	{
		List<KnapsackGood> list = new List<KnapsackGood>();

		BaseProperty baseProperty_Ring = new BaseProperty(1, "Ring", "传说\n梅戒  攻击 +10 防御 +100\n\nwww.liujunliang.com.cn   by 即歩", 10, 100, 80, "UI/Good (1)", KnapsackGood.GoodType.Consumable, KnapsackGood.GoodQuality.Common);
		Consumable good_Ring = new Consumable(10, 10, baseProperty_Ring);

        BaseProperty baseProperty_Hat = new BaseProperty(2, "Hat", "绝世\n无视宝帽  攻击 +200 防御 +70\n\nwww.liujunliang.com.cn   by 即歩", 10, 100, 100, "UI/Good (17)", KnapsackGood.GoodType.Equipment, KnapsackGood.GoodQuality.Epic);
        Equipment good_Hat = new Equipment(100, 50, 30, 50, Equipment.EquitmentType.Head, baseProperty_Hat);

        BaseProperty baseProperty_Wing = new BaseProperty(3, "Wing", "天下无双\n天使的翅膀  攻击 +10 速度 +100\n\nwww.liujunliang.com.cn   by 即歩", 10, 100, 100, "UI/Good (2)", KnapsackGood.GoodType.Equipment, KnapsackGood.GoodQuality.Legendary);
        Equipment good_Wing = new Equipment(100, 50, 30, 50, Equipment.EquitmentType.Neck, baseProperty_Wing);

        BaseProperty baseProperty_Cloth = new BaseProperty(4, "Cloth", "稀有\n占灵宝甲  攻击 -10 防御 +200\n\nwww.liujunliang.com.cn   by 即歩", 10, 100, 100, "UI/Good (3)", KnapsackGood.GoodType.Equipment, KnapsackGood.GoodQuality.Rare);
        Equipment good_Cloth = new Equipment(100, 50, 30, 50, Equipment.EquitmentType.Shoulder, baseProperty_Cloth);

        BaseProperty baseProperty_Shoes = new BaseProperty(5, "Shoes", "稀有\n急速战靴  攻击 -10 防御 +200\n\nwww.liujunliang.com.cn   by 即歩", 10, 100, 100, "UI/Good (8)", KnapsackGood.GoodType.Equipment, KnapsackGood.GoodQuality.Rare);
        Equipment good_Shoes = new Equipment(100, 50, 30, 50, Equipment.EquitmentType.Leg, baseProperty_Shoes);

        BaseProperty baseProperty_Sword = new BaseProperty(6, "Sword", "绝世\n独孤九剑  攻击 +200 防御 +70\n\nwww.liujunliang.com.cn   by 即歩", 10, 100, 100, "UI/Good (21)", KnapsackGood.GoodType.Weapon, KnapsackGood.GoodQuality.Uncommon);
        Weapon good_Sword = new Weapon(100, Weapon.WeaponType.MainHand, baseProperty_Sword);

		BaseProperty baseProperty_Axe = new BaseProperty(7,"Axe", "绝世\n巨凌战斧  攻击 +100 防御 +50\n\nwww.liujunliang.com.cn   by 即歩",10,100,100, "UI/Good (6)",KnapsackGood.GoodType.Weapon,KnapsackGood.GoodQuality.Uncommon);
        Weapon good_Axe = new Weapon(50, Weapon.WeaponType.OffHand, baseProperty_Axe);

		list.Add(good_Ring);
        list.Add(good_Hat);
		list.Add(good_Wing);
        list.Add(good_Cloth);
        list.Add(good_Shoes);
        list.Add(good_Sword);
		list.Add(good_Axe);

		//生成Json
		string json = JsonMapper.ToJson(list);

		string path = Application.streamingAssetsPath + "/GoodJson.json";


		#region 文件流方式写入文件
		/*将json内容打包进文件，最好不要转化编码
        //将Json信息保存进文件
        using ( FileStream fileStream = File.Create(path))//创建文件流
        {
            //byte[] bt = System.Text.ASCIIEncoding.UTF8.GetBytes(json);//创建文件缓冲区

            //将Json写入到文件内
            fileStream.Write(bt,0,bt.Length);

            //清空缓冲区、关闭文件流
            fileStream.Flush();
            fileStream.Close();
        }
		*/
		#endregion

		StreamWriter sw = new StreamWriter(path);
		sw.Write(json);
		sw.Close();
	}
}
